package vue.graphique;

import java.awt.Dimension;
import java.awt.Graphics;
import java.util.Scanner;

import javax.swing.JPanel;

public class VuePlateau extends JPanel {
	private static final long serialVersionUID = -6470029206190670491L;
	
	// Variable(s) d'instance
	private String plateau = null;
	
	// Constructeur(s)
	public VuePlateau () {
		super();
		
		this.setPreferredSize(new Dimension(600, 600));
	}
	
	// Methode(s)
	public void paintComponent(Graphics g) {
		Scanner sc = null;
		String valeurCase;
		if(plateau != null) {
			sc = new Scanner(this.plateau);
		}
		for(int i = 0; i < 600; i+=120) {
			for(int j = 0; j < 600; j+=120) {
				if(sc != null && sc.hasNext()) {
					valeurCase=sc.next();
					if(valeurCase.equals("X")) {
						g.fillRect(j, i, 120, 120);
					} else {
						if(valeurCase.equals("O")) {
							g.drawRect(j, i, 120, 120);
						} else {
							g.drawRect(j, i, 120, 120);
							g.fillOval(j, i, 120, 120);
						}
					}
				} else {
					g.drawRect(j, i, 120, 120);
				}
			}
		}
	}
	
	public void dessinerPlateau(String plateau) {
		this.plateau=plateau;
		this.repaint();
	}
}
